home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.app;
-
- import com.extensibility.print.PageFormatDialog;
- import com.extensibility.util.Debug;
- import com.extensibility.xml.URI;
- import java.awt.Component;
- import java.awt.event.ActionEvent;
- import java.io.File;
- import java.io.IOException;
- import java.io.Writer;
- import java.util.Enumeration;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import javax.swing.event.EventListenerList;
- import javax.swing.undo.UndoableEditSupport;
-
- public class BaseDocument {
- static int nextUntitledIndex = 1;
- URI baseURI;
- boolean touched;
- boolean virgin;
- int untitledIndex;
- protected WindowUndoManager undoManager;
- protected UndoableEditSupport undoSupport;
- EventListenerList listenerList;
- ChangeEvent changeEvent;
-
- public BaseDocument(URI var1) {
- this.listenerList = new EventListenerList();
- this.changeEvent = new ChangeEvent(this);
- this.baseURI = var1;
- this.undoManager = new WindowUndoManager(this);
- this.undoSupport = new UndoableEditSupport();
- this.undoSupport.addUndoableEditListener(new UndoAdapter(this));
- }
-
- public BaseDocument() {
- this(new URI());
- this.virgin = true;
- this.untitledIndex = nextUntitledIndex++;
- }
-
- public void setURI(URI var1) {
- this.baseURI = var1;
- if (!this.baseURI.hasPersistence()) {
- this.untitledIndex = nextUntitledIndex++;
- }
-
- Enumeration var2 = Desktop.getWindowsOfDocument(this);
-
- while(var2.hasMoreElements()) {
- ((BaseWindow)var2.nextElement()).setTitle();
- }
-
- }
-
- public void touch() {
- this.touched = true;
- this.virgin = false;
- }
-
- public boolean isTouched() {
- return this.touched;
- }
-
- public final boolean isVirgin() {
- return this.virgin;
- }
-
- public final void setVirgin(boolean var1) {
- this.virgin = var1;
- if (var1) {
- this.touched = false;
- }
-
- }
-
- public void setTouched(boolean var1) {
- if (var1) {
- this.touch();
- } else {
- this.touched = var1;
- }
-
- }
-
- public final boolean isReadOnly() {
- return false;
- }
-
- public URI getURI() {
- return this.baseURI;
- }
-
- public String getName() {
- return !this.baseURI.hasPersistence() ? String.valueOf(UI.getString("untitled.window")).concat(String.valueOf(this.untitledIndex == 1 ? "" : String.valueOf("").concat(String.valueOf(this.untitledIndex)))) : this.baseURI.getUIName();
- }
-
- public BaseWindow getWindow(Class var1) {
- return Desktop.findWindow(new 1(var1, this));
- }
-
- public WindowUndoManager getUndoManager() {
- return this.undoManager;
- }
-
- public void startCommand() {
- this.undoSupport.beginUpdate();
- }
-
- public void endCommand() {
- this.undoSupport.endUpdate();
- }
-
- public void performEdit(BaseEdit var1) {
- var1.doCommand();
- this.undoSupport.postEdit(var1);
- }
-
- public String getClassName() {
- return "com.extensibility.xa.BaseDocument";
- }
-
- public void printSetup(ActionEvent var1) {
- PageFormatDialog var2 = DialogFactory.askPageSetup(Desktop.getDialogParent(var1));
- if (!var2.userCanceled()) {
- BaseApplication.getPreferences().updateMargins(var2.getPreferences());
- }
- }
-
- protected String[] getSaveChangesName() {
- return new String[]{this.getName()};
- }
-
- public boolean isOkToClose(BaseWindow var1) {
- if (var1 instanceof EditWindow && !((EditWindow)var1).commitPendingEdits(true)) {
- return false;
- } else if (this.isTouched() && Desktop.isLastWindowOfDocument(var1)) {
- int var2 = DialogFactory.saveChanges(var1, this.getSaveChangesName());
- if (var2 == 0) {
- return this.save(new ActionEvent(var1, 1001, "#DUMMY"));
- } else if (var2 == 1) {
- this.cleanupUnsavedChanges();
- return true;
- } else {
- return false;
- }
- } else {
- return true;
- }
- }
-
- public void saveNotify(URI var1) {
- }
-
- protected Writer createWriter(URI var1) throws IOException {
- return var1.createWriter();
- }
-
- public boolean save(ActionEvent var1) {
- if (!this.isReadOnly() && !this.baseURI.isEmpty()) {
- if (!this.isTouched()) {
- return true;
- } else {
- try {
- Writer var2 = this.createWriter(this.baseURI);
- this.write(var2);
- var2.close();
- } catch (Exception var4) {
- DialogFactory.showException((Component)null, 103, var4, this.getName());
- boolean var3 = false;
- return var3;
- }
-
- this.setTouched(false);
- BaseApplication.getApplication().saveNotify(this.getURI(), this);
- return true;
- }
- } else {
- return this.saveAs(var1);
- }
- }
-
- protected File getSaveAsFile(ActionEvent var1) {
- String[] var2 = BaseApplication.getApplication().getSaveTypes();
- String var3 = "";
- return DialogFactory.askNewFile(Desktop.getDialogParent(var1), var2, var3);
- }
-
- public boolean saveAs(ActionEvent var1) {
- File var2 = this.getSaveAsFile(var1);
- if (var2 == null) {
- return false;
- } else {
- this.setURI(new URI(var2));
- this.touch();
- this.save(var1);
- return true;
- }
- }
-
- public boolean saveAs(URI var1) {
- this.setURI(var1);
- this.touch();
- return this.save((ActionEvent)null);
- }
-
- public void close() {
- BaseApplication.getApplication().fireDocumentClosed(this.getURI());
- }
-
- public void read(URI var1) throws Exception {
- Debug.assertAbstract();
- }
-
- public void write(Writer var1) throws IOException {
- Debug.assertAbstract();
- }
-
- public void addChangeListener(ChangeListener var1) {
- this.listenerList.add(Class.forName("javax.swing.event.ChangeListener"), var1);
- }
-
- public void removeChangeListener(ChangeListener var1) {
- this.listenerList.remove(Class.forName("javax.swing.event.ChangeListener"), var1);
- }
-
- protected void cleanupUnsavedChanges() {
- }
-
- protected void fireChangeEvent() {
- Object[] var1 = this.listenerList.getListenerList();
-
- for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
- if (var1[var2] == Class.forName("javax.swing.event.ChangeListener")) {
- ChangeListener var3 = (ChangeListener)var1[var2 + 1];
- var3.stateChanged(this.changeEvent);
- }
- }
-
- }
-
- public int getDefaultDocWidth() {
- return Desktop.getDefaultDocWidth(this);
- }
-
- public int getDefaultDocHeight() {
- return Desktop.getDefaultDocHeight(this);
- }
- }
-